package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation(value = "护理项目分页条件查询")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(@ApiParam("护理项目名称") @RequestParam(required = false) String name,
                                                                    @ApiParam("状态") @RequestParam(required = false)Integer status,
                                                                    @ApiParam("当前页码") @RequestParam(required = true,defaultValue = "1")Integer pageNum,
                                                                    @ApiParam("每页显示条数") @RequestParam(required = true,defaultValue = "10")Integer pageSize){
        PageResponse<NursingProjectVo> response=nursingProjectService.getByPage(name,status,pageNum,pageSize);

        return ResponseResult.success(response);
    }

    @PostMapping
    @ApiOperation(value = "新增")
    public ResponseResult insertNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.insertNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        NursingProjectVo nursingProjectVo=nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @PutMapping("{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseResult deleteNursingProject(@PathVariable Long id){
        nursingProjectService.deleteNursingProject(id);
        return ResponseResult.success();
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult<NursingProjectVo> selectAllNursingProject(){
        List<NursingProjectVo> nursingProjectVo=nursingProjectService.selectAllNursingProject();
        return ResponseResult.success(nursingProjectVo);
    }


}
